/*
Copyright (C) 1996-1997 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#include "fxVSIncludes.fx"

struct VS_WATER
{
	float4 Position: POSITION;
	float2 TexCoord0: TEXCOORD;
	float2 TexCoord1: WARPCOORD;
};

struct PS_WATER
{
	float4 Position: SV_POSITION;
	float2 TexCoord0: TEXCOORD0;
	float2 TexCoord1: TEXCOORD1;
};

#ifdef VERTEXSHADER
PS_WATER WaterVS (VS_WATER vs_in)
{
	PS_WATER vs_out;

	vs_out.Position = mul (EntityMatrix, mul (LocalMatrix, vs_in.Position));
	vs_out.TexCoord0 = vs_in.TexCoord0;
	vs_out.TexCoord1 = vs_in.TexCoord1 + WarpTime;

	return vs_out;
}
#endif


#ifdef PIXELSHADER
float4 DoWaterWarp (float3 fcolor, float3 fogvec, float2 tc0, float2 tc1)
{
/*
	// because the warp effect can produce different gradients for the texcoord, and therefore select different miplevels
	// as it warps, we select using fixed gradients derived from the unwarped texcoord
	float4 diff = tex2Dgrad (diffSampler, tc0 + sin (tc1) * 0.125f, ddx (tc0), ddy (tc0));
	float FogFactor = PS_GetFogFactor (fogvec);

	return float4 (lerp (fcolor, diff.rgb, FogFactor), Alpha);
*/
}

float4 WaterPS (PS_WATER ps_in) : SV_TARGET0
{
	float4 diff = surfTexture.SampleGrad (
		surfSampler,
		ps_in.TexCoord0 + sin (ps_in.TexCoord1) * 0.125f,
		ddx (ps_in.TexCoord0),
		ddy (ps_in.TexCoord0)
	);

	return float4 (diff.rgb, Alpha);
}
#endif

